package org.csu.petserver.web;



import org.apache.ibatis.annotations.Param;
import org.csu.petserver.domain.Client;
import org.csu.petserver.domain.Order;
import org.csu.petserver.service.ClientInfo;
import org.csu.petserver.service.OrderInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import java.util.List;

@SessionAttributes(value = {"clients"})
@Controller
public class ClientController {

    @Autowired
    ClientInfo clientInfo;

    List<Client> clients;

    @Autowired
    OrderInfo orderInfo;

    @GetMapping("/Client/viewClient")
    String viewClient(Model model){
         clients=clientInfo.allClient();
         model.addAttribute("clients",clients);
         return "/Client/viewClient";
    }

    @GetMapping("/Client/clientOrder")
    String viewClientOrder(Model model, @Param("clientId") String clientId){
        List<Order> orders=clientInfo.findOrderByClient(clientInfo.findClientById(clientId));
        model.addAttribute("orders",orders);
        return "/viewOrders";
    }
}
